package cn.dhnep;

import cn.dhnep.demo.pojo.vo.RespBean;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 * @author hwl
 * @since  2021-08-16
 */
@RestControllerAdvice
public class    GlobalExceptionHandler {

    /**
     * 捕捉 BindException
     * pojo.frontvo 实体的注解抛出的异常
     */
    @ExceptionHandler(BindException.class)
    public RespBean entityException(BindException e) {
        String msg = e.getBindingResult().getFieldError().getDefaultMessage();
        return RespBean.error(msg);
    }
}
